/*
 * @Author: lixu lixu@puchigames.com
 * @Date: 2025-01-03 16:49:48
 * @LastEditors: lixu lixu@puchigames.com
 * @LastEditTime: 2025-09-16 17:59:04
 * @FilePath: /go-helper/ixRedis/transaction.go
 * @Description: Redis 事务操作
 */
package ixRedis

import "github.com/garyburd/redigo/redis"

// Multi 开始事务
func (c *Client) Multi() error {
	conn, err := c.getConn()
	if err != nil {
		return err
	}
	defer conn.Close()

	_, err = conn.Do("MULTI")
	return err
}

// Exec 执行事务
func (c *Client) Exec() ([]interface{}, error) {
	conn, err := c.getConn()
	if err != nil {
		return nil, err
	}
	defer conn.Close()

	return redis.Values(conn.Do("EXEC"))
}

// Discard 取消事务
func (c *Client) Discard() error {
	conn, err := c.getConn()
	if err != nil {
		return err
	}
	defer conn.Close()

	_, err = conn.Do("DISCARD")
	return err
}
